package com.jihui.user.dao.impl;

import com.jihui.user.model.JihuiUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface UserMapper {

    @Insert("insert into jihui_user(username , password) values (#{jihuiUser.username},#{jihuiUser.password})")
    @SelectKey(before = false, keyProperty = "jihuiUser.id", resultType = Long.class, statementType = StatementType.STATEMENT, statement = "SELECT LAST_INSERT_ID() AS id")
    void save(@Param("jihuiUser") JihuiUser jihuiUser);

    List<JihuiUser> findList(JihuiUser jihuiUser);

    /**
     * 根据主键查询实体
     *
     * @param userId 主键
     * @return 实体
     */
    @Select("select * from jihui_user where id=#{userId}")
    @ResultMap("UserResultMap")
    JihuiUser findById(@Param("userId") Long userId);
    /**
     * 根据用户名查询实体
     *
     * @param username 用户名
     * @return 实体
     */
    @Select("select * from jihui_user where username=#{username}")
    @ResultMap("UserResultMap")
    JihuiUser findByUsername(@Param("username") String username);
    /**
     * 根据主键删除实体
     *
     * @param primaryKey 主键
     */
    void delete(Long primaryKey);
}